import axios from "axios"
import { Promise } from "core-js"

axios.interceptors.request.use(
    config => {
        config.baseURL = "/api"
        const token = localStorage.getItem("token")
        if (token) {
            config.headers.authorization = `Bearer ${token}`
        }
        return config
    },
    err => Promise.reject(err)
)

const isDEV = process.env.NODE_ENV === "development"
console.log(process.env.NODE_ENV);

axios.interceptors.response.use(
    res => res.data,
    err => {
        if (isDEV) {
            console.log("err", err.response.data);
        }
        return Promise.reject(err.response.data)
    }
)

export const lazyRequest = (request, deply = 1000) => {
    const promise = new Promise((resolve) => {
        setTimeout(resolve, deply);
    })
    return Promise.all([request, promise])
}

export default axios


